<template>
	<view class="container">
		<view class="status_bar">
			<view></view>
			<image @tap="toPage('/pages/mine/account/qrCode')" style="width: 25px;height: 25px;"
				src="../../static/image/mydt.png"></image>
		</view>
		<!--头部-->
		<view class="head flex-row" @tap="toPage('/pages/mine/account/account')">
			<!-- 头像 -->
			<view class="flex-row" @tap="toPage('/pages/mine/account/account')">
				<!-- <image v-if="userInfo.avatar" :src="userInfo.avatar" class="face"></image> -->
				<image v-if="userInfo.user_avatar_file_name"
					:src="`http://chat.zwsmcn.com:8090/UserAvatarDownloader?action=ad&user_uid=${userInfo.user_uid}&user_local_cached_avatar=${userInfo.user_avatar_file_name}&enforceDawnload=1&token=`"
					class="face">
				</image>
				<image v-else src="../../static/img/face.png" class="face"></image>
				<!-- <view class="face1" v-else>{{userInfo.nickname[0]}}</view> -->

			</view>
			<view class="info-box">
				<!-- 昵称会员标签 -->
				<view class="info-name">
					<view style="font-size: 40upx;font-weight: bold;">
						{{userInfo.nickname?userInfo.nickname:''}}
					</view>
					<view style="margin-top: 10upx;">
						<image v-if="userInfo.is_beau==0" src="../../static/image/vip/V1@3x.png"
							style="width: 46upx; height: 46upx; margin-left: 20upx;"></image>
						<image v-if="userInfo.is_beau==1" src="../../static/image/vip/V4@3x.png"
							style="width: 46upx; height: 46upx; margin-left: 20upx;"></image>
					</view>
				</view>

				<view class="info-num">账号:{{userInfo.user_uid }}</view>
				<!-- <view class="copybtns">信誉值:0</view> -->
			</view>
			<view></view>
			<view></view>
			<view></view>
			<view></view>
			<view>
				<image src="../../static/image/user/set-on@3x.png" mode=""
					style="width: 50upx;height: 50upx;margin-top: 20upx;"></image>
			</view>
		</view>
		<!-- <view class="items flex-row">
			<text class="label">账号</text>
			<text class="value">{{ user.telephone }}</text>
		</view> -->

		<!-- <view @tap="uploadFace" class="items flex-row">
			<text class="label">头像</text>
			<view class="flex-row">
				<image v-if="user.face" :src="user.face" class="face"></image>
				<image v-else src="../../static/img/face.png" class="face"></image>
				<uni-icons type="arrowright" size="18" color="#999"></uni-icons>
			</view>
		</view> -->
		<view class="vip-box" @tap="toPage('/pages/mine/vipOpen/vipOpen')">
			<view>
				<view style="color: #9d683c; font-weight: bold;">开通VIP会员</view>
				<view style="color: #997448; font-size: 28upx;">尊享会员权益</view>
			</view>
			<view class="vip-btn">立即开通</view>
		</view>

		<view class="shop-box">
			<view style="border-bottom: 1px solid #eaeaea; display: flex;"
				@tap="toPage('/pages/mine/vipOpen/announcement')">
				<view style="width: 50upx;margin-top: 10upx;">
					<image src="../../static/image/aaa.png" mode=""></image>
				</view>
				<u-notice-bar :text="dataBoardTitle" color="#000" bgColor="#fff" icon=""></u-notice-bar>
			</view>
			<view class="con-shop" @tap="toPage('/pages/mine/shop/shop')">
				<view style="display: flex;">
					<image src="../../static/image/user/user-icon01@3x.png" mode=""></image>
					<view style="margin-top: 13upx;">星聊商城</view>
				</view>
				<image style="width: 16px;height: 16px;padding: 0;margin-top: 10px;" src="../../static/image/right.png">
				</image>
			</view>
		</view>
		<view class="shop-box" style="margin-bottom: 100upx;">
			
			

			
			<view class="con-shop" @tap="toPage('/pages/mine/shop/myCollect')">
				<view style="display: flex;">
					<image src="../../static/image/user/user-icon04@3x.png" mode=""></image>
					<view style="margin-top: 10upx;">我的收藏</view>
				</view>
				<image style="width: 16px;height: 16px;padding: 0;margin-top: 10px;" src="../../static/image/right.png">
				</image>
			</view>
			
			<view class="con-shop" @tap="toPage('/pages/mine/shop/privacySecurity')">
				<view style="display: flex;">
					<image src="../../static/image/user/user-icon06@3x.png" mode=""></image>
					<view style="margin-top: 10upx;">隐私安全</view>
				</view>
				<image style="width: 16px;height: 16px;padding: 0;margin-top: 10px;" src="../../static/image/right.png">
				</image>
			</view>

		</view>


		<!-- <view @tap="logout" class="main-btn flex-column">退出登录</view> -->

		<!--修改名称-->
		<uni-popup ref="edit">
			<view class="dialog">
				<view class="title">我的昵称</view>
				<input class="input" v-model="nickname" type="text" placeholder="请输入群聊名称" />
				<view @tap="editAction" class="btn" :class="{disabled: !nickname}">完成</view>
				<view @tap="cancelEdit" class="close">
					<uni-icons type="closeempty" size="26" color="#999"></uni-icons>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				userId: uni.getStorageSync('user_uid') || '',
				user: {},
				nickname: '',
				text1: 'uView UI众多组件覆盖开发过程的各个需求，组件功能丰富，多端兼容。让您快速集成，开箱即用',
				userInfo: {},
				dataBoardTitle: ''
			}
		},
		onShow() {
			this.getUser()
			this.getBoardList()
			this.getmemberwallet()
		},
		onLoad() {
			this.getfriendlist();
		},
		methods: {
			// 获取钱包状态
			getmemberwallet() {
				uni.request({
					url: 'https://www.zwsmcn.com/api/index_new/getmemberwallet',
					header: {
						'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
					},
					data: {
						userid: uni.getStorageSync('user_uid'),
					},
					method: 'POST',
					success: res => {
						this.step = res.data.is_wallet

					},
					fail: res => {
						//console.log(res);
					}
				});
			},
			// 钱包跳转
			gopage() {
				if (this.step == 1) {
					this.toPage('/pages/discover/wallet_info')
				} else(
					this.toPage('/pages/discover/money')
				)

			},
			logout() {
				
				// uni.clearStorageSync()
				uni.MBSocketProvider.closeLocalSocket();
				uni.setStorageSync('loginInfo', {});
				uni.setStorageSync('token', '')
				uni.setStorageSync('user_uid', '')
				uni.setStorageSync('userId', '')
				uni.setStorageSync('user_level', '')
				uni.setStorageSync('nickname', '')
				uni.setStorageSync('user_avatar_file_name', '')
				uni.setStorageSync('loginInfoArr', []);
				this.toPage('/pages/login')
			},
			showEdit() {
				this.groupName = this.group.name
				this.$refs.edit.open()
			},
			cancelEdit() {
				this.$refs.edit.close()
			},
			editAction() {
				if (this.$validate.isNull(this.groupName)) return
				this.$util.loading('保存中')
				uni.request({
					method: 'POST',
					url: this.$api.updateGroupName,
					data: {
						groupId: this.groupId,
						userId: this.userId,
						name: this.groupName
					},
					header: this.$util.getHeader(),
					success: res => {
						uni.hideLoading()
						this.$util.toast(res.data.msg)
						if (!res.data.code) {
							this.$refs.edit.close()
							this.group.name = this.groupName
							uni.setStorageSync('groupName', this.groupName)
						}
					},
					fail: res => {
						uni.hideLoading()
						this.$util.toast('保存失败')
					}
				})
			},
			// 上传头像
			uploadFace() {
				uni.chooseImage({
					count: 1,
					success: chooseRes => {
						const tempFilePaths = chooseRes.tempFilePaths

						this.$util.loading('上传中')
						tempFilePaths.forEach(temp => {
							uni.uploadFile({
								url: this.$api.uploadUserFace,
								filePath: temp,
								formData: {
									groupId: this.groupId,
									userId: this.userId
								},
								name: 'file',
								header: this.$util.getHeader(),
								success: uploadRes => {
									uni.hideLoading()
									if (uploadRes.data.code) return
									let data = JSON.parse(uploadRes.data)
									this.user.face = this.$api.staticPath + data.data
									uni.setStorageSync('userFace', this.user.face)
								}
							})
						})
					}
				})
			},
			// 获取信息
			getUser() {
				uni.request({
					url: this.$api.baseUrl + '/api/user/detail',
					header: {
						'content-type': 'application/json'
					},
					data: {
						user_uid: uni.getStorageSync('user_uid'),
					},
					method: 'POST',
					success: res => {
						console.log(res, 'res');
						// uni.hideLoading()
						if (res.data.code == 0) {
							this.userInfo = res.data.data
							uni.setStorageSync('nickname', this.userInfo.nickname)
							uni.setStorageSync('user_avatar_file_name', this.userInfo.user_avatar_file_name)


							uni.setStorageSync('user_level', this.userInfo.user_level)

						
						}
						// this.list = res.data;
					},
					fail: res => {
						console.log(res);
					}

				})
			},

			getfriendlist() {
				console.log('getfriendlist');
				const requestData = {
					"processorId": '1008',
					"jobDispatchId": '2',
					"actionId": '7',
					"newData": uni.getStorageSync('user_uid')
				};
				const requestDataJsonStr = JSON.stringify(requestData);
				uni.request({
					url: 'http://chat.zwsmcn.com:8090/rest_post',
					header: {
						'content-type': 'application/json'
					},
					data: requestDataJsonStr,
					method: 'POST',
					success: res => {

						uni.hideLoading()


						let originalArray_res = JSON.parse(res.data.returnValue)
						let originalArray = []

						let friends = [];
						let nicknamehashMap = new Map();;
						let avatarhashMap = new Map();
						// this.DB.isTable("friend" + uni.getStorageSync("user_uid")).then((res) => {
						// 	// console.log(res);
						// 	if (!res) {
						// 		let sql =
						// 			'id INTEGER PRIMARY KEY AUTOINCREMENT, nickname text, userAvatarFileName text, user_mail text, user_sex text, user_uid text, online text,whatsUp text, online_time text,ex10 text,friendRemark text';
						// 		this.DB.createTable("friend" + uni.getStorageSync(
						// 				"user_uid"), sql)
						// 			.then(res_f => {
						// 				console.log("创建friend表成功", res_f);
						// 			})
						// 			.catch(error => {
						// 				console.log("创建表失败", error);
						// 			});
						// 	} else {
						// 		this.DB.deleteTableData("friend" + uni.getStorageSync(
						// 				"user_uid"))
						// 			.then(res => {
						// 				console.log("删除表数据成功", res);


						// 			})
						// 			.catch(error => {
						// 				console.log("删除失败", error);
						// 			});
						// 	}
						// })
						originalArray_res.map(item => {
							item.online_time = item.ex13.length > 0 ? (item.ex13.length > 10 ? item
								.ex13 : item.ex13 + '000') : Math.floor(uni.MBUtils
								.getCurrentUTCTimestamp());
							originalArray.push(item);

							friends.push({
								id: item.user_uid,
								name: item.nickname
							})


							nicknamehashMap.set(item.user_uid, item.nickname);


							avatarhashMap.set(item.user_uid, item.userAvatarFileName);
							uni.setStorageSync('avatarhashMap', JSON.stringify(Array.from(
								avatarhashMap)))
							uni.setStorageSync('nicknamehashMap', JSON.stringify(Array.from(
								nicknamehashMap)))



							let online_time = item
								.online_time; // item.status_time ??Math.floor(uni.MBUtils.getCurrentUTCTimestamp())


							let sql1 =
								`'${item.nickname}', '${item.userAvatarFileName}', '${item.user_mail}', '${item.user_sex}', '${item.user_uid}', '${item.online}', '${item.whatsUp}','${online_time}','${item.ex10}','${item.friendRemark}'`;

							let condition =
								'nickname , userAvatarFileName , user_mail , user_sex , user_uid , online ,whatsUp ,online_time,ex10,friendRemark';
							// #ifdef APP
							this.DB.insertTableData("friend" + uni.getStorageSync("user_uid"), sql1,
									condition)
								.then(res => {

								})
								.catch(error => {
									console.log("失败", error);

									if (error.code == '-1404' || error.code == -1404) {
										// this.createfriendTable();
									}
								});

							// #endif
						})
					
					},
					fail: res => {
						console.log(res);
					}
				});
			},
			//公告
			getBoardList() {
				uni.request({
					url: this.$api.baseUrl + '/api/common/notice/fetch',
					header: {
						'content-type': 'application/json'
					},
					data: {
						//user_uid: uni.getStorageSync('user_uid'),
						page: 1,
						page_size: 20
					},
					method: 'POST',
					success: res => {
						console.log(res, 'res');
						// uni.hideLoading()
						if (res.data.code == 0) {
							this.dataBoardTitle = res.data.data[0].title
						}
						console.log(this.list);
						// this.list = res.data;
					},
					fail: res => {
						console.log(res);
					}

				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	// page {
	// 	background-color: #999;
	// }
	.status_bar {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-right: 34rpx;


	}

	.status_bar,
	.head {
		background-color: #fff;
		height: 140upx;
		margin-top: 25px;
		margin-right: 20upx;

		.face {

			width: 160upx;
			height: 160upx;
			border-radius: 10px;
			margin-top: 30upx;
		}

		.face1 {
			background-color: rgb(234, 66, 15);
			width: 130upx;
			height: 130upx;
			text-align: center;
			line-height: 130upx;
			border-radius: 10px;
			margin-top: 30upx;
			color: #ffffff;
			font-size: 24px;
		}

		.info-name {

			display: flex;
			align-items: center;
		}

		.info-num {
			// width: 56upx;
			padding: 2upx 30upx;
			background: #f0f4f7;
			border-radius: 30upx;
			margin-top: 40upx;
		}

		// .copybtns {
		// 	color: #4457a4;
		// 	margin-top: 40upx;
		// }
	}

	.items {
		height: 100upx;
		padding: 0 30upx;
		background-color: #FFF;
		border-bottom: 2upx solid #F2F2F2;

		.label {
			color: #666;
			font-size: 32upx;
		}

		.value {
			color: #999;
			font-size: 30upx;
		}

		.face {
			width: 100upx;
			height: 100upx;
			border-radius: 10upx;
		}
	}

	.main-btn {
		color: red;
		height: 100upx;
		padding: 0 30upx;
		margin-top: 100upx;
		background-color: #FFF;
	}

	.vip-box {
		width: 92%;
		height: 150upx;
		margin-left: 4%;
		margin-top: 45upx;
		border-radius: 20upx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background: url(../../static/image/user/user-v-bg@3x.png) no-repeat;
		background-size: 100%;
		padding: 40upx;

		.vip-btn {
			color: #fedeab;
			padding: 12upx 42.5upx;
			border-radius: 60upx;
			font-weight: 200;
			background: linear-gradient(to right, #7a4114, #905c2a);

		}
	}

	.shop-box {
		width: 92%;
		margin-left: 4%;
		background-color: #fff;
		margin-top: 20upx;
		border-radius: 20upx;
		padding: 10upx 30upx;
		box-shadow: 0 0 40upx #d6e7f1; // 左
		box-shadow: 0 0 40upx #d6e7f1; // 右
		color: #2e2e2e;
		font-weight: 300;

		image {
			width: 40upx;
			height: 40upx;
			padding: 10upx 28upx 0upx 10upx;
		}

	}

	.con-shop {
		height: 100upx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	// .dialog {
	// 	width: 600upx;
	// 	height: 460upx;
	// 	padding: 0 40upx;
	// 	border-radius: 10upx;
	// 	background-color: #FFF;
	// 	position: relative;

	// 	.close {
	// 		position: absolute;
	// 		right: 20upx;
	// 		top: 20upx;
	// 	}

	// 	.title {
	// 		height: 120upx;
	// 		font-size: 32upx;
	// 		text-align: center;
	// 		line-height: 120upx;
	// 	}

	// 	.input {
	// 		height: 80upx;
	// 		padding: 0 30upx;
	// 		border-radius: 10upx;
	// 		margin: 40upx 0 80upx;
	// 		border: 2upx solid #ddd;
	// 	}

	// 	.btn {
	// 		color: #FFF;
	// 		height: 80upx;
	// 		line-height: 80upx;
	// 		text-align: center;
	// 		border-radius: 10upx;
	// 		background-color: #2CA246;

	// 		&.disabled,
	// 		&:active {
	// 			opacity: 0.8;
	// 		}
	// 	}
	// }
</style>